package org.komarichin.jdo.persistence;

import com.google.appengine.api.datastore.Link;
import com.google.appengine.api.datastore.Text;
import org.komarichin.beans.INews;

import javax.jdo.annotations.*;
import java.util.Date;

/**
 * User: Michael Komarichin
 * Date: 14.10.2009
 * Time: 10:48:20
 */
@PersistenceCapable(identityType = IdentityType.APPLICATION)
public class News implements INews {
    @PrimaryKey
    @Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
    private static final long serialVersionUID = -7061634412959444379L;
    private Long id;
    @Persistent
    private String title;
    @Persistent
    private String name;
    @Persistent
    private String description;
    @Persistent
    private String keyWords;
    @Persistent
    private Long user;
    @Persistent
    private Date create;
    @Persistent
    private Date update;
    @Persistent
    private Link source;
    @Persistent
    private Text content;

    @Override
    public Long getId() {
        return id;
    }

    @Override
    public void setId(Long id) {
        this.id = id;
    }

    @Override
    public String getTitle() {
        return title;
    }

    @Override
    public void setTitle(String title) {
        this.title = title;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public void setName(String name) {
        this.name = name;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public void setDescription(String description) {
        this.description = description;
    }

    @Override
    public String getKeyWords() {
        return keyWords;
    }

    @Override
    public void setKeyWords(String keyWords) {
        this.keyWords = keyWords;
    }

    @Override
    public Long getUser() {
        return user;
    }

    @Override
    public void setUser(Long user) {
        this.user = user;
    }

    @Override
    public Date getCreate() {
        return create;
    }

    @Override
    public void setCreate(Date create) {
        this.create = create;
    }

    @Override
    public Date getUpdate() {
        return update;
    }

    @Override
    public void setUpdate(Date update) {
        this.update = update;
    }

    @Override
    public Link getSource() {
        return source;
    }

    @Override
    public void setSource(Link source) {
        this.source = source;
    }

    @Override
    public Text getContent() {
        return content;
    }

    @Override
    public void setContent(Text content) {
        this.content = content;
    }

    @Override
    public String toString() {
        final StringBuilder sb = new StringBuilder();
        sb.append("News");
        sb.append("{id=").append(id);
        sb.append(", title='").append(title).append('\'');
        sb.append(", name='").append(name).append('\'');
        sb.append(", description='").append(description).append('\'');
        sb.append(", keyWords='").append(keyWords).append('\'');
        sb.append(", user=").append(user);
        sb.append(", create=").append(create);
        sb.append(", update=").append(update);
        sb.append(", source=").append(source);
        sb.append(", content=").append(content);
        sb.append('}');
        return sb.toString();
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof News)) return false;

        News news = (News) o;

        if (content != null ? !content.equals(news.content) : news.content != null) return false;
        if (create != null ? !create.equals(news.create) : news.create != null) return false;
        if (description != null ? !description.equals(news.description) : news.description != null) return false;
        if (id != null ? !id.equals(news.id) : news.id != null) return false;
        if (keyWords != null ? !keyWords.equals(news.keyWords) : news.keyWords != null) return false;
        if (name != null ? !name.equals(news.name) : news.name != null) return false;
        if (source != null ? !source.equals(news.source) : news.source != null) return false;
        if (title != null ? !title.equals(news.title) : news.title != null) return false;
        if (update != null ? !update.equals(news.update) : news.update != null) return false;
        if (user != null ? !user.equals(news.user) : news.user != null) return false;

        return true;
    }

    @Override
    public int hashCode() {
        int result = id != null ? id.hashCode() : 0;
        result = 31 * result + (title != null ? title.hashCode() : 0);
        result = 31 * result + (name != null ? name.hashCode() : 0);
        result = 31 * result + (description != null ? description.hashCode() : 0);
        result = 31 * result + (keyWords != null ? keyWords.hashCode() : 0);
        result = 31 * result + (user != null ? user.hashCode() : 0);
        result = 31 * result + (create != null ? create.hashCode() : 0);
        result = 31 * result + (update != null ? update.hashCode() : 0);
        result = 31 * result + (source != null ? source.hashCode() : 0);
        result = 31 * result + (content != null ? content.hashCode() : 0);
        return result;
    }
}
